import config from "@/config"
import http from "@/utils/request"

import axios from 'axios'
let Host = `${config.API_URL}` // 登录
    // let hrp = 'http://39.103.143.154:54322/api'
    // params 都必须带 token
    // import env from './../../config/dev.env'
    // export const setCommonHeader = (token) => axios.defaults.headers.common['Token'] = token;

// 添加请求拦截器
axios.interceptors.request.use(function(config) {
    // 在发送请求之前做些什么
    return config;
}, function(error) {
    // 对请求错误做些什么
    return Promise.reject(error);
});
export const table = (params) => axios({
    method: 'GET',
    url: Host + '/table',
    data: params
})

export default {
    ver: {
        url: `${config.API_URL}/demo/ver`,
        name: "获取最新版本号",
        get: async function(params) {
            return await http.get(this.url, params);
        }
    },
    post: {
        url: `${config.API_URL}/demo/post`,
        name: "分页列表",
        post: async function(data) {
            return await http.post(this.url, data, {
                headers: {
                    //'response-status': 401
                }
            });
        }
    },
    page: {
        url: `${config.API_URL}/demo/page`,
        name: "分页列表",
        get: async function(params) {
            return await http.get(this.url, params);
        }
    },
    list: {
        url: `${config.API_URL}/demo/list`,
        name: "数据列表",
        get: async function(params) {
            return await http.get(this.url, params);
        }
    },
    menu: {
        url: `${config.API_URL}/demo/menu`,
        name: "普通用户菜单",
        get: async function() {
            return await http.get(this.url);
        }
    },
    status: {
        url: `${config.API_URL}/demo/status`,
        name: "模拟无权限",
        get: async function(code) {
            return await http.get(this.url, {}, {
                headers: {
                    "response-status": code
                }
            });
        }
    },
    table: {
        url: `${config.API_URL}/table`,
        name: "table",
        get: async function(params) {
            return await http.get(this.url, params);
        }
    },
    searchTableByName: {
        url: `${config.API_URL}/searchTableByName`,
        name: "searchTableByName",
        get: async function(params) {
            return await http.get(this.url, params);
        }
    }
}